package com.dehui.traders.ui.market.rankdetail;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.TextAppearanceSpan;
import android.widget.TextView;

import com.dehui.traders.R;
import com.dehui.traders.adapter.TableAdapter;
import com.dehui.traders.bean.IndexInfo;
import com.dehui.traders.bean.PlateListBean;
import com.dehui.traders.widgets.MyHScrollView;

import java.util.List;

import me.goldze.mvvmhabit.utils.Utils;

/**
 * Created by hqq on 18.4.25.
 */

public class TheRankDetailAdapter extends TableAdapter<PlateListBean.PlateData> {

    private static final int Index_TheNew = 0;
    private static final int Index_ZhangFu = 1;
    private static final int Index_ZhangDie = 2;
    private static final int Index_ZhengFu = 3;
    private static final int Index_ChengJiaoGuShu = 4;
    private static final int Index_ChengJiaoE = 5;
    private static final int Index_Kai = 6;
    private static final int Index_Shou = 7;
    private static final int Index_High = 8;
    private static final int Index_Low = 9;
    private static final int Index_ZongShiZhi = 10;
    private Activity activity;

    public TheRankDetailAdapter(Context context, List mDatas, Activity activity) {
        super(context, mDatas);
        this.activity = activity;
    }

    @Override
    public void setFragment(MyHScrollView scrollview) {
        scrollview.setActivity(activity);
    }

    @Override
    public void setItemText(int position, TextView tv, PlateListBean.PlateData item) {
        double cha = Double.valueOf(item.price) - Double.valueOf(item.closePrice);
        switch (position) {
            case Index_TheNew:
                tv.setText(Utils.doubleToString(item.price));
                if (cha < 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.green));
                } else if (cha > 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                } else {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.white));
                }
                break;
            case Index_ZhangFu:
                double s = (item.price - item.closePrice) * 100 / (float) item.closePrice;
                tv.setText(Utils.doubleToString(s) + "%");
                tv.setTextColor(Color.RED);
                if (cha < 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.green));
                } else if (cha > 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                } else {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.white));
                }
                break;
            case Index_ZhangDie:
                tv.setText(Utils.doubleToString(item.price - item.closePrice));
                if (cha < 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.green));
                } else if (cha > 0) {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                } else {
                    tv.setTextColor(ContextCompat.getColor(mContext, R.color.white));
                }
                break;
            case Index_ZhengFu:
                tv.setText(Utils.StringToString(item.swing));
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.green));
                break;
            case Index_ChengJiaoGuShu:
                tv.setText(item.volumn);
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                break;
            case Index_ChengJiaoE:
                tv.setText(item.volumnPrice);
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.green));
                break;
            case Index_Kai:
                tv.setText(Utils.doubleToString(item.openPrice));
                tv.setTextColor(ContextCompat.getColor(mContext,R.color.red));
                break;
            case Index_Shou:
                tv.setText(Utils.doubleToString(item.closePrice));
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                break;
            case Index_High:
                tv.setText(Utils.doubleToString(item.highPrice));
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                break;
            case Index_Low:
                tv.setText(Utils.doubleToString(item.lowPrice));
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                break;
            case Index_ZongShiZhi:
                tv.setText(item.totalValue);
                tv.setTextColor(ContextCompat.getColor(mContext, R.color.red));
                break;
        }

    }

    @Override
    public SpannableString setTv0(PlateListBean.PlateData item) {
        String title = item.name + "\n" + item.code.substring(2);
        SpannableString styledText = new SpannableString(title);
        styledText.setSpan(new TextAppearanceSpan(mContext, R.style.style_title_0), 0, item.name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        styledText.setSpan(new TextAppearanceSpan(mContext, R.style.style_title_1), item.name.length(), title.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return styledText;
    }

    @Override
    public int getL() {
        return 11;
    }


}
